{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e503ec1a",
   "metadata": {},
   "source": [
    "# 元组的不可变性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "56458904",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a', 'e', 'I', 'o', 'u']"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vowels=list(\"aeiou\")\n",
    "vowels[2]=\"I\"\n",
    "vowels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "443116ac",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'tuple' object does not support item assignment",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [2]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m vowels2\u001b[38;5;241m=\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124ma\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124me\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mI\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mo\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mu\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m----> 2\u001b[0m vowels2[\u001b[38;5;241m2\u001b[39m]\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mI\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m      3\u001b[0m vowels2\n",
      "\u001b[1;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"
     ]
    }
   ],
   "source": [
    "vowels2=('a', 'e', 'I', 'o', 'u')\n",
    "vowels2[2]=\"I\"\n",
    "vowels2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "5de4df9e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "str"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 元组与字符串的区别\n",
    "t=('python')\n",
    "type(t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "66dbafa8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tuple"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t=('python',)\n",
    "type(t)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "46a0baaf",
   "metadata": {},
   "source": [
    "# 字典嵌套字典"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "2bfbd4b2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'ford': {'name': 'ford prefect', 'gender': 'male', 'occuption': 'reseracher'}}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "people={}\n",
    "people['ford']={\"name\":\"ford prefect\",\n",
    "               \"gender\":\"male\",\n",
    "               \"occuption\":\"reseracher\"}\n",
    "people"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "2ad043b1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'ford': {'name': 'ford prefect', 'gender': 'male', 'occuption': 'reseracher'},\n",
       " 'qqq': {'name': 'e prefect', 'gender': 'fmale', 'occuption': 'photographer'},\n",
       " 'gfj': {'name': 'gfhrefect', 'gender': 'fmale', 'occuption': 'editor'},\n",
       " 'df': {'name': 'gsdfgfect', 'gender': 'male', 'occuption': 'scripwriter'}}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "people['qqq']={\"name\":\"e prefect\",\n",
    "               \"gender\":\"fmale\",\n",
    "               \"occuption\":\"photographer\"}\n",
    "people['gfj']={\"name\":\"gfhrefect\",\n",
    "               \"gender\":\"fmale\",\n",
    "               \"occuption\":\"editor\"}\n",
    "people['df']={\"name\":\"gsdfgfect\",\n",
    "               \"gender\":\"male\",\n",
    "               \"occuption\":\"scripwriter\"}\n",
    "people"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "20153ed7",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pprint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "1a1b9ef6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'df': {'gender': 'male', 'name': 'gsdfgfect', 'occuption': 'scripwriter'},\n",
      " 'ford': {'gender': 'male', 'name': 'ford prefect', 'occuption': 'reseracher'},\n",
      " 'gfj': {'gender': 'fmale', 'name': 'gfhrefect', 'occuption': 'editor'},\n",
      " 'qqq': {'gender': 'fmale', 'name': 'e prefect', 'occuption': 'photographer'}}\n"
     ]
    }
   ],
   "source": [
    "pprint.pprint(people)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "634a19c2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'male'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "people['df'][\"gender\"]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
